<template>
  <div v-loading="loading" class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('股权架构') }}</span>
    </div>
    <StructureChart :chart-data="chartData" />
    <div class="area-header">
      <span class="area-header-title">{{ $t('股东信息') }}</span>
    </div>
    <el-row>
      <el-table :data="hhqyEquityStructureList" border>
        <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
          <template slot-scope="scope">
            {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
          </template>
        </el-table-column>
        <el-table-column :label="$t('股东名称')" align="center" prop="name" />
        <el-table-column :label="$t('持股比例(%)')" align="center" prop="shareholdingRatio" width="180" />
        <el-table-column :label="$t('投资金额') + $t('金额单位')" align="center" prop="investAmount" width="180">
          <template slot-scope="scope">
            <span>{{ moneyFormat(scope.row.investAmount, 'w') }}</span>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-row>
    <div class="area-header" style="margin-top: 10px;">
      <span class="area-header-title">{{ $t('下属合伙企业') }}</span>
    </div>
    <el-row>
      <el-table :data="form.hhqyChangeShareholders" class="nowrapTable formTable" border>
        <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
          <template slot-scope="scope">
            {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
          </template>
        </el-table-column>
        <el-table-column :label="$t('股东名称')" align="center" prop="hhqyChangeName" />
        <el-table-column :label="$t('持股比例(%)')" align="center" prop="shareholdingRatio" />
        <el-table-column :label="$t('投资金额') + $t('金额单位')" align="center" prop="investAmount">
          <template slot-scope="scope">
            <span>{{ moneyFormat(scope.row.investAmount, 'w') }}</span>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="subHhqyTotal>0"
        :total="subHhqyTotal"
        :page.sync="subHhqyPage.pageNum"
        :limit.sync="subHhqyPage.pageSize"
        @pagination="findSubHhqyByHhqyId"
      />
    </el-row>
  </div>
</template>

<script>
import { listHhqyEquityStructure, delHhqyEquityStructure, exportHhqyEquityStructure, structureChartData } from '@/api/hhqy/structure/hhqyEquityStructure'
import { findSubHhqyByHhqyId } from '@/api/hhqy/changehistory/hhqyChangeHistory'
import StructureChart from '@/views/hhqy/structure/StructureChart'
export default {
  components: { StructureChart },
  data() {
      return {
          // 遮罩层
          loading: true,
          // 总条数
          total: 0,
          chartData: {},
          // 股权架构表格数据
          hhqyEquityStructureList: [],
          // 弹出层标题
          title: '',
          // 是否显示弹出层
          formOpen: false,
          // 查询参数
          queryParams: {
              pageNum: 1,
              pageSize: 10,
              hhqyId: this.$route.query.id
          },
        // 下属合伙企业查询分页
        subHhqyPage: {
          hhqyId: undefined,
          pageNum: 1,
          pageSize: 10
        },
        subHhqyTotal: 0,
          // 表单参数
          form: {},
          // 表单校验
          rules: {}
      }
  },
  created() {
      this.getList()
  },
  methods: {
    /** 查询股权架构列表 */
    getList() {
        this.loading = true
        listHhqyEquityStructure(this.queryParams).then(response => {
            this.hhqyEquityStructureList = response.rows
            this.total = response.total
            this.findSubHhqyByHhqyId()
            this.loading = false
        })
        structureChartData(this.$route.query.id).then(response => {
          this.chartData = response.data
        })
    },
    // 查询下属合伙企业
    findSubHhqyByHhqyId: async function() {
      this.subHhqyPage.hhqyId = this.$route.query.id
      await findSubHhqyByHhqyId(this.subHhqyPage).then(response => {
        this.form.hhqyChangeShareholders = response.rows
        this.subHhqyTotal = response.total
      })
    },
    // 表单重置
    reset() {
        this.form = {
            id: undefined,
            name: undefined,
            shareholdingRatio: undefined,
            investAmount: undefined,
            delFlag: undefined,
            createBy: undefined,
            updateBy: undefined,
            createTime: undefined,
            updateTime: undefined
        }
        this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
        this.queryParams.pageNum = 1
        this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
        this.resetForm('queryForm')
        this.queryHandle()
    },
    /** 新增按钮操作 */
    addHandle() {
        this.formOpen = true
        this.title = this.$t('股权架构')
        this.$nextTick(() => {
            this.$refs.hhqyEquityStructureForm.init(null)
        })
    },
    /** 修改按钮操作 */
    updateHandle(row) {
        this.formOpen = true
        this.title = this.$t('股权架构')
        this.$nextTick(() => {
            // 调用form页面的 init 方法初始化数据
            this.$refs.hhqyEquityStructureForm.init(row)
        })
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
        this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText: this.$t('取消'),
            type: 'warning'
        }).then(function() {
            return delHhqyEquityStructure(row.id)
        }).then(() => {
            this.getList()
            this.msgSuccess(this.$t('删除成功'))
        }).catch(function() {
        })
    },
    /** 导出按钮操作 */
    exportHandle() {
        const queryParams = this.queryParams
        this.$confirm(this.$t('是否确认导出?'), this.$t('警告'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText: this.$t('取消'),
            type: 'warning'
        }).then(function() {
            return exportHhqyEquityStructure(queryParams)
        }).then(response => {
            this.download(response.msg)
        }).catch(function() {
        })
    }
  }
}
</script>
